package com.woniuxy.service.impl;

import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.woniuxy.entity.Perms;
import com.woniuxy.entity.Roles;
import com.woniuxy.mapper.RolesPermsMapper;
import com.woniuxy.service.LogService;
import com.woniuxy.service.RolesPermsService;

@Service
public class RolesPermsServiceImpl implements RolesPermsService {

	@Autowired
	private RolesPermsMapper rolesPermsMapper;
	@Autowired
	private LogService logService;

	@Override
	public List<Perms> findPermsByRid(int ro_id) {

		return rolesPermsMapper.findPermsByRid(ro_id);
	}

	@Override
	public List<Roles> findRolesPerms() {

		return rolesPermsMapper.findRolesPerms();
	}

	@Override
	public List<Roles> findRolesByUid(int u_id) {
		
		return rolesPermsMapper.findRolesByUid(u_id);
	}

	@Override
	public List<Perms> allPerms() {
		
		return rolesPermsMapper.allPerms();
	}

	@Override
	public List<Roles> allRoles() {
		
		return rolesPermsMapper.allRoles();
	}

	@Override
	public Boolean updateUserRoles(int u_id, int[] ro_ids) {
		
		int n=rolesPermsMapper.delUserRoles(u_id);
		int y=rolesPermsMapper.addUserRoles(u_id, ro_ids);
		
		return n > 0 && y > 0;
	}

	@Override
	public Boolean updateRolesPerms(int ro_id, int[] pe_ids) {
		
		int n=rolesPermsMapper.delRolesPerms(ro_id);
		int y=rolesPermsMapper.addRolesPerms(ro_id, pe_ids);
		
		return n > 0 && y > 0;
	}

}
